﻿namespace Chameleon.Storage
{
	using Microsoft.WindowsAzure.StorageClient;
	using System.Collections.Generic;
	using System.Linq;

	/// <summary>
	/// Provides an entry point for accessing an Azure Storage context.
	/// </summary>
	
	internal sealed class AzureStorageContainer : IStorageContainer
	{
		#region Fields

			/// <summary>
			/// Azure container represented by the current instance.
			/// </summary>
			
			CloudBlobContainer Container;

		#endregion


		#region Methods

			/// <summary>
			/// Returns the collection of items in the container.
			/// </summary>
			
			public IEnumerable<IStorageItem> Items()
			{
				return
					from i in Container.ListBlobs().Cast<CloudBlob>()
					select new AzureStorageItem( i );
			}


			/// <summary>
			/// Returns the specified storage item in the container.
			/// </summary>
			/// <param name="name">The name of the item or an absolute URI to the item.</param>

			public IStorageItem Item( string name )
			{
				return new AzureStorageItem( Container.GetBlobReference( name ) );
			}

		#endregion


		#region Constructors

			/// <summary>
			/// Initializes a new instance to represent the specified container.
			/// </summary>
			/// <param name="container">Azure storage container to be represented.</param>
			
			internal AzureStorageContainer( CloudBlobContainer container )
			{
				Container = container;
			}

		#endregion
	}
}
